<%@ page language="java" isELIgnored="false"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>私教课程管理</title>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
	<script src="/admin/public/html5shiv.min.js"></script>
	<script src="/admin/public/respond.min.js"></script>
<![endif]-->
<!-- Bootstrap core CSS -->
<link href="/admin/public/bootstrap.min.css" title="" rel="stylesheet" />
<link href="/admin/font-awesome/css/font-awesome.css" rel="stylesheet">
<link href="/admin/css/plugins/chosen/chosen.css" rel="stylesheet">
<link href="/admin/font-awesome/css/font-awesome.min.css"
	rel="stylesheet" />
<link href="/admin/public/animate.css" rel="stylesheet" />
<link rel="stylesheet" href="/admin/public/inspinia.css" />
<link rel="stylesheet" href="/admin/css/pop-up.css" />
<link rel="stylesheet" href="/admin/css/plugins/toastr/toastr.min.css" />
<link rel="stylesheet" type="text/css"
	href="${request.getContext }/admin/css/xcConfirm.css" />
<script src="/admin/My97/WdatePicker.js"></script>
<script type="text/javascript" charset="utf-8" src="/admin/js/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/admin/js/ueditor.all.js"> </script>
<script type="text/javascript" charset="utf-8" src="/admin/js/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="/admin/js/ueditor.all.min.js"></script>
<style type="text/css">
.img{
	height: 214px;
	width:640px;
}
</style>
</head>
<body>
	<div id="wrapper" class="container">
		<div class="wrapper wrapper-content">
			<div class="right_box">
				<div style="border: none; box-shadow: none;" class="right_one row">
					<div class="col-md-12 col-sm-12 col-xs-12" style="float: left;">
						<form class="form-horizontal" method="post" id="savecourses" enctype="multipart/form-data"
							novalidate="novalidate">
							<input value="1" name="coursesType" type="hidden" />
							<input value="${coursesInfoId }" name="coursesInfoId" type="hidden" />
							<input value="${picUrl }" name="oldPicUrl" type="hidden" />
							<div class="form-group">
								<label class="col-lg-2 control-label">私教课程:</label>
								<div class="col-lg-6">
									<input type="text" class="form-control" id="coursesName"
										name="coursesName" value="${coursesName }"/>
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">时长(分钟):</label>
								<div class="col-lg-6">
									<input onkeyup="value=value.replace(/[^0-9]/g,&#39;&#39;);" type="text" class="form-control" id="minTime"
										name="minTime" value="${minTime }"/>
								</div>
							</div>
							<div style="display: none" >
							<div class="form-group">
								<label class="col-lg-2 control-label">背景图片:</label>
								<div class="col-lg-6">
									<input type="file" class="form-control" id="picUrl"
										name="picUrl" value="${picUrl }" onchange="preview(this,1)">
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label"></label>
								<div class="col-lg-6">
									<span style="color:red;">建议图片尺寸：640*214</span>
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label"></label>
								<div class="col-lg-6">
									<div id="preview1">
										<img src="${picUrl }" alt="" height="214px" width="640px"/>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">如何上课:</label>
								<div class="col-lg-6">
									<div>
										<script id="editor" type="text/plain" name="rhsk"   style="width:504px;height:200px;"></script>
									</div>
										<input type="hidden" id="mainContent" name="mainContent">
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">课程标签:</label>
								<div class="col-lg-6">
									<textarea  rows="3" cols="3" class="form-control" id="jianjie"
										name="jianjie" >${jianjie }</textarea>
								</div>
							</div>
							</div>
							<div class="form-group" style="height:200px; margin-left: 5px" >
								<label class="font-noraml">关联教练:</label>
								<div class="input-group">
									<select data-placeholder="--请选择--" class="chosen-select" multiple style="width:350px;" tabindex="4">
										<c:forEach items="${elist }" var="item">
											<option value="${item.userId }">${item.realname }</option>
										</c:forEach>
									</select>
								</div>
							</div>
							<input type="button" onclick="savecourses();" id="btnn" style="display: none"/>
							<input type="button" onclick="update();" id="xiugai" style="display: none"/>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script src="/admin/public/jquery-1.11.3.js"></script>
		<script src="/admin/js/plugins/chosen/chosen.jquery.js"></script>
	<script src="/admin/public/bootstrap.min.js" type="text/javascript"></script>
	<script src="${request.getContext }/admin/js/xcConfirm.js"
		type="text/javascript" charset="utf-8"></script>
	<script src="/admin/js/plugins/toastr/toastr.min.js"></script>
	<script src="/admin/js/new_page.js"></script>
	<script src="/admin/js/jquery.form.min.js"></script>
	<script type="text/javascript">
	var config = {
			'.chosen-select': {},
			'.chosen-select-deselect': {
				allow_single_deselect: true
			},
			'.chosen-select-no-single': {
				disable_search_threshold: 10
			},
			'.chosen-select-no-results': {
				no_results_text: 'Oops, nothing found!'
			},
			'.chosen-select-width': {
				width: "95%"
			}
		}
		for(var selector in config) {
			$(selector).chosen(config[selector]);
		}
		function preview(file, i) {
			var prevDiv = document.getElementById('preview' + i);
			if (file.files && file.files[0]) {
				var reader = new FileReader();
				reader.onload = function(evt) {
					prevDiv.innerHTML = '<img class="img" src="' + evt.target.result + '" />';
				}
				reader.readAsDataURL(file.files[0]);
			} else {
				prevDiv.innerHTML = '<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
			}
		}
	</script>
	<script>
		function check() {
			var coursesName = $("#coursesName").val();
			var minTime = $("#minTime").val();
			var minNum = $("#minNum").val();
			var maxNum=$("#maxNum").val();
			var userIdlength=$(".chosen-container .chosen-choices .search-choice span").length;
			if (coursesName.length == 0) {
				alertNew('请输入私教课名称！', false);
				return false;
			}
			if (minTime.length == 0) {
				alertNew('请输入最少时长！', false);
				return false;
			}
			if (userIdlength == 0) {
				alertNew('请选择关联教练！', false);
				return false;
			} 
			return true;
		}
		//添加
		function savecourses() {
			if (check()) {
				var len=$(".chosen-container .chosen-choices .search-choice span").length;
				var zhi=""
				var zhi2=""
				for(var i=0;i<len;i++){
					zhi2=$(".chosen-container .chosen-choices .search-choice span").eq(i).data("value");
					if(i==0){
						zhi=zhi2;
					}else{
						zhi += ("," +zhi2);
					}
				}
				$('#savecourses').ajaxSubmit({
					type : "post",
					data : {"userId":zhi},
					enctype:"multipart/form-data",
					dataType : "json",
					url : "/courses/addInfo",
					success : function(data) {
						if (data.success) {
							window.wxc.xcConfirm(data.msg, window.wxc.xcConfirm.typeEnum.info,{onOk:function(){ 
								$('#ifr', window.parent.document).attr('src',
								'/courses/cournfo?coursesType=1');
					  		}})
						}else{
							alertNew(data.msg, false);
						}
					},
					error : function(data) {
						alert("很抱歉，未知的错误发生了！");
					}
				});
			}
		}
		//修改
		function update() {
			if (check()) {
				var len=$(".chosen-container .chosen-choices .search-choice span").length;
				var zhi=""
				var zhi2=""
				for(var i=0;i<len;i++){
					zhi2=$(".chosen-container .chosen-choices .search-choice span").eq(i).data("value");
					if(i==0){
						zhi=zhi2;
					}else{
						zhi += ("," +zhi2);
					}
				}
				$('#savecourses').ajaxSubmit({
					type : "post",
					data : {"userId":zhi},
					dataType : "json",
					enctype:"multipart/form-data",
					url : "/courses/updatecourses",
					success : function(data) {
						if (data.success) {
							window.wxc.xcConfirm(data.msg, window.wxc.xcConfirm.typeEnum.info,{onOk:function(){ 
								$('#ifr', window.parent.document).attr('src',
								'/courses/cournfo?coursesType=1');
					  		}})
						}else{
							alertNew(data.msg, false);
						}
					},
					error : function(data) {
						alert("很抱歉，未知的错误发生了！");
					}
				});
			}
		}
		 /**文本编辑器**/
        //实例化编辑器
 //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
  var ue = UE.getEditor('editor', {
 	 	"imageActionName": "uploadimage", /* 执行上传图片的action名称 */
 	    "imageFieldName": "upfile", /* 提交的图片表单名称 */
 	    "imageMaxSize": 2048000, /* 上传大小限制，单位B */
 	    "imageAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 上传图片格式显示 */
 	    "imageCompressEnable": false, /* 是否压缩图片,默认是true */
 	    "imageCompressBorder": 1600, /* 图片压缩最长边限制 */
 	    "imageInsertAlign": "none", /* 插入的图片浮动方式 */
 	    "imageUrlPrefix": "", /* 图片访问路径前缀 */
 	    "imagePathFormat": "/upload/content/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
 	                                /* {filename} 会替换成原文件名,配置这项需要注意中文乱码问题 */
 	                                /* {rand:6} 会替换成随机数,后面的数字是随机数的位数 */
 	                                /* {time} 会替换成时间戳 */
 	                                /* {yyyy} 会替换成四位年份 */
 	                                /* {yy} 会替换成两位年份 */
 	                                /* {mm} 会替换成两位月份 */
 	                                /* {dd} 会替换成两位日期 */
 	                                /* {hh} 会替换成两位小时 */
 	                                /* {ii} 会替换成两位分钟 */
 	                                /* {ss} 会替换成两位秒 */
 	                                /* 非法字符 \ : * ? " < > | */
 	                                /* 具请体看线上文档: fex.baidu.com/ueditor/#use-format_upload_filename */
 	                                
			    	   /* 上传视频配置 */
			    "videoActionName": "uploadvideo", /* 执行上传视频的action名称 */
			    "videoFieldName": "upfile", /* 提交的视频表单名称 */
			    "videoPathFormat": "/upload/content/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
			    "videoUrlPrefix": "", /* 视频访问路径前缀 */
			    "videoMaxSize": 734003200, /* 上传大小限制，单位B，默认100MB 此处限制700M*/
			    "videoAllowFiles": [
			        ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
			        ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid"], /* 上传视频格式显示 */
 	        
 	        /* 上传文件配置 */
 	        "fileActionName": "uploadfile", /* controller里,执行上传视频的action名称 */
 	        "fileFieldName": "upfile", /* 提交的文件表单名称 */
 	        "filePathFormat": "/upload/content/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
 	        "fileUrlPrefix": "", /* 文件访问路径前缀 */
 	        "fileMaxSize": 51200000, /* 上传大小限制，单位B，默认50MB */
 	        "fileAllowFiles": [
 	            ".png", ".jpg", ".jpeg", ".gif", ".bmp",
 	            ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
 	            ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
 	            ".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
 	            ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
 	        ], /* 上传文件格式显示 */
 	        serverUrl: '/admin/content/uploadimage'
 });
	</script>
</body>
</html>
